home *** CD-ROM | disk | FTP | other *** search
- /* MPW C Application skeleton by Dean Yu */
- /* Initialisation routines */
-
- #include <Types.h>
- #include <AppleEvents.h>
- #include <Dialogs.h>
- #include <Fonts.h>
- #include <GestaltEqu.h>
- #include <Menus.h>
- #include <Quickdraw.h>
- #include <ToolUtils.h>
- #include <Traps.h>
- #include <Windows.h>
-
- #include "globals.h"
- #include "appleEventHandlers.h"
- #include "eventHandler.h"
- #include "menuDispatch.h"
- #include "trapAvail.h"
- #include "WindowExtensions.h"
-
- /* Private routine prototypes */
-
- static void InitStuff(void);
- static void SetUpMenus(void);
- static void SetUpWindows(void);
- static void SetupRecordingFloater(void);
- static void SetupToolsFloater(void);
- static void SetUpLimits(void);
- static void SetUpAppleEvents(void);
-
- extern void _DataInit();
-
- void main()
- {
- UnloadSeg((Ptr) _DataInit);
-
- MaxApplZone();
-
- InitStuff();
- EventLoop();
- }
-
- void InitStuff()
- {
- EventRecord firstEvent;
- OSErr gestaltError;
- long gestaltResponse;
-
- InitGraf((Ptr) &qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- InitDialogs(nil);
- InitCursor();
-
- if (!TrapAvailable(_Gestalt)) /* Look for _Gestalt */
- FatalErrorAlert(kSystemVersionTooOld);
-
- WaitNextEvent(everyEvent, &firstEvent, 60, nil);
- FlushEvents(everyEvent, 0);
-
- /* Check to see if certain features are implemented */
-
- gestaltError = Gestalt(gestaltAppleEventsAttr, &gestaltResponse); /* Check for AppleEvents™ */
- if (!gestaltError)
- {
- if ((gestaltResponse & (1 << gestaltAppleEventsPresent)) == 0)
- FatalErrorAlert(kNoAppleEvents);
- }
- else
- FatalErrorAlert(kGestaltError);
-
- gestaltError = Gestalt(gestaltPPCToolboxAttr, &gestaltResponse); /* Check for PPC Toolbox */
- if (gestaltError)
- FatalErrorAlert(kGestaltError);
-
- SetUpMenus();
- SetUpWindows();
- SetUpLimits();
- SetUpAppleEvents();
- }
-
-
- /* Get the menu bar from resource fork. Fill menu with DAs. Draw it */
-
- void SetUpMenus()
- {
- Handle theMenu;
-
- theMenu = GetNewMBar(rMbarID);
- SetMenuBar(theMenu);
- DisposHandle(theMenu);
- AddResMenu(GetMHandle(rAppleMenuID),'DRVR');
- DisableItem(GetMHandle(rEditMenuID), 0);
- CheckItem(GetMHandle(rFloatersMenuID), kRecordingItem, true);
- CheckItem(GetMHandle(rFloatersMenuID), kToolsItem, true);
- DrawMenuBar();
- }
-
- /*
- Set up any windows needed by the application
- */
-
- void SetUpWindows()
- {
- SetupRecordingFloater();
- SetupToolsFloater();
-
- gActivateEventHandler = NewActivateHandlerProc(&ActivateEventHandler);
- }
-
- void SetupRecordingFloater()
- {
- Rect theRect;
- PicHandle recordingControlsPicture;
- OSErr error;
-
- recordingControlsPicture = (PicHandle) GetPicture(128);
- theRect = (**recordingControlsPicture).picFrame;
- OffsetRect(&theRect, 70, 70);
-
- gRecordingFloaterActivateHandler = NewActivateHandlerProc(&RecordingFloaterActivateHandler);
- error = NewWindowReference(&gRecordingFloater, &theRect, "\pRecord", true, kHasPaletteTitlebarMask,
- (WindowRef) -1, 0, gRecordingFloaterActivateHandler);
- SetWindowPic((WindowPtr) gRecordingFloater, recordingControlsPicture);
- }
-
- void SetupToolsFloater()
- {
- Rect theRect;
- PicHandle toolsPicture;
- OSErr error;
-
- toolsPicture = (PicHandle) GetPicture(130);
- theRect = (**toolsPicture).picFrame;
- OffsetRect(&theRect, 170, 100);
-
- gToolsFloaterActivateHandler = NewActivateHandlerProc(&ToolsFloaterActivateHandler);
- error = NewWindowReference(&gToolsFloater, &theRect, "\pTools", true, kHasPaletteTitlebarMask,
- (WindowRef) -1, 0, gToolsFloaterActivateHandler);
- SetWindowPic((WindowPtr) gToolsFloater, toolsPicture);
- }
-
- /*
- Set up areas for the screen in which windows can be dragged and sized.
- */
-
- void SetUpLimits()
- {
- RgnHandle deskTop;
-
- deskTop = GetGrayRgn();
- gDragArea = (**deskTop).rgnBBox;
- SetRect(&gGrowBounds, 48, 48,
- ((gDragArea.right) - (gDragArea.left)),((gDragArea.bottom) - (gDragArea.top)));
- }
-
- /* Set up the AppleEvent dispatch table */
-
- void SetUpAppleEvents()
- {
- OSErr installAppleEventError;
-
- installAppleEventError = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, (AEEventHandlerUPP) &OAPPHandler, 0, false);
- installAppleEventError = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, (AEEventHandlerUPP) &ODOCHandler, 0, false);
- installAppleEventError = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, (AEEventHandlerUPP) &PDOCHandler, 0, false);
- installAppleEventError = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, (AEEventHandlerUPP) &QUITHandler, 0, false);
-
- if (installAppleEventError)
- FatalErrorAlert(kAEInstallError);
- }
-